using AForge.Video;
using AForge.Video.DirectShow;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace SilverSea.Video.Tools
{
	public class VideoCaptureDeviceSettingPage : UserControl, IVideoSourcePage
	{
		private IContainer icontainer_0;
		private Label label1;
		private ComboBox cbxDevice;
		private Label label2;
		private ComboBox cbxDesiredFrameRate;
		private ComboBox cbxDesiredFrameSize;
		private Label label3;
		private CheckBox chkUsingDeinterlaceFilter;
		private ComboBox cbxDeinterlaceFilterName;
		private Label label4;
		private Button btnFindFilter;
		private Label label5;
		private ComboBox cbxVideoDecoder;
		private ComboBox cbxChanel;
		private Label label6;
		private FilterInfoCollection filterInfoCollection_0;
		private EventHandler eventHandler_0;
		private bool bool_0;
		private string string_0 = string.Empty;
		private string string_1 = string.Empty;
		private int int_0 = 1;
		private int int_1;
		private string string_2 = "Standard";
		public event EventHandler StateChanged
		{
			add
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public bool Completed
		{
			get
			{
				return this.bool_0;
			}
		}
		public string VideoSource
		{
			get
			{
                return this.filterInfoCollection_0[this.cbxDevice.SelectedIndex].MonikerString;
			}
			set
			{
				for (int i = 0; i < this.filterInfoCollection_0.Count; i++)
				{
					if (this.filterInfoCollection_0[i].MonikerString == value)
					{
						this.cbxDevice.SelectedIndex = i;
						return;
					}
				}
			}
		}
		public string Login
		{
			get
			{
				return this.string_0;
			}
			set
			{
				this.string_0 = value;
			}
		}
		public string Password
		{
			get
			{
				return this.string_1;
			}
			set
			{
				this.string_1 = value;
			}
		}
		public int StreamType
		{
			get
			{
				return this.int_0;
			}
			set
			{
				this.int_0 = value;
			}
		}
		public int ProtocolType
		{
			get
			{
				return this.int_1;
			}
			set
			{
				this.int_1 = value;
			}
		}
		public int Chanel
		{
			get
			{
				return this.cbxChanel.SelectedIndex;
			}
			set
			{
				this.cbxChanel.SelectedIndex = value;
			}
		}
		public string Resolution
		{
			get
			{
				return this.cbxDesiredFrameSize.Text;
			}
			set
			{
				this.cbxDesiredFrameSize.Text = value;
			}
		}
		public string Quality
		{
			get
			{
				return this.string_2;
			}
			set
			{
				this.string_2 = value;
			}
		}
		public int FrameRate
		{
			get
			{
				return this.cbxDesiredFrameRate.SelectedIndex;
			}
			set
			{
				this.cbxDesiredFrameRate.SelectedIndex = value;
			}
		}
		public bool UsingDeinterlaceFilter
		{
			get
			{
				return this.chkUsingDeinterlaceFilter.Checked;
			}
			set
			{
				this.chkUsingDeinterlaceFilter.Checked = value;
			}
		}
		public string DeinterlaceFilterName
		{
			get
			{
				return this.cbxDeinterlaceFilterName.Text;
			}
			set
			{
				this.cbxDeinterlaceFilterName.Text = value;
			}
		}
		public int UsingPlugins
		{
			get
			{
				return this.cbxVideoDecoder.SelectedIndex;
			}
			set
			{
				if (value <= 2)
				{
					this.cbxVideoDecoder.SelectedIndex = value;
					return;
				}
				this.cbxVideoDecoder.SelectedIndex = 0;
			}
		}
		public VideoCaptureDeviceSettingPage()
		{
			this.InitializeComponent();
			try
			{
				this.filterInfoCollection_0 = new FilterInfoCollection(FilterCategory.VideoInputDevice);
				if (this.filterInfoCollection_0.Count == 0)
				{
					throw new ApplicationException();
				}
				foreach (FilterInfo filterInfo in this.filterInfoCollection_0)
				{
					this.cbxDevice.Items.Add(filterInfo.Name);
				}
				this.bool_0 = true;
			}
			catch (ApplicationException)
			{
				this.cbxDevice.Items.Add("No local capture devices");
				this.cbxDevice.Enabled = false;
			}
			this.cbxDevice.SelectedIndex = 0;
			this.cbxDesiredFrameRate.SelectedIndex = 0;
			this.cbxDesiredFrameSize.SelectedIndex = 0;
			this.cbxChanel.SelectedIndex = 0;
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.label1 = new Label();
			this.cbxDevice = new ComboBox();
			this.label2 = new Label();
			this.cbxDesiredFrameRate = new ComboBox();
			this.cbxDesiredFrameSize = new ComboBox();
			this.label3 = new Label();
			this.chkUsingDeinterlaceFilter = new CheckBox();
			this.cbxDeinterlaceFilterName = new ComboBox();
			this.label4 = new Label();
			this.btnFindFilter = new Button();
			this.label5 = new Label();
			this.cbxVideoDecoder = new ComboBox();
			this.cbxChanel = new ComboBox();
			this.label6 = new Label();
			base.SuspendLayout();
			this.label1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(7, 20);
			this.label1.Margin = new Padding(4, 0, 4, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(83, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "Video Device";
			this.cbxDevice.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxDevice.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbxDevice.Location = new System.Drawing.Point(90, 17);
			this.cbxDevice.Margin = new Padding(4);
			this.cbxDevice.Name = "cbxDevice";
			this.cbxDevice.Size = new System.Drawing.Size(306, 24);
			this.cbxDevice.TabIndex = 3;
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(157, 81);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(124, 16);
			this.label2.TabIndex = 5;
			this.label2.Text = "Desired Frame Rate";
			this.cbxDesiredFrameRate.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxDesiredFrameRate.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbxDesiredFrameRate.Items.AddRange(new object[]
			{
				"Uncontrolled",
				"1",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9",
				"10",
				"11",
				"12",
				"13",
				"14",
				"15",
				"16",
				"17",
				"18",
				"19",
				"20",
				"21",
				"22",
				"23",
				"24",
				"25",
				"26",
				"27",
				"28",
				"29",
				"30"
			});
			this.cbxDesiredFrameRate.Location = new System.Drawing.Point(286, 78);
			this.cbxDesiredFrameRate.Name = "cbxDesiredFrameRate";
			this.cbxDesiredFrameRate.Size = new System.Drawing.Size(110, 24);
			this.cbxDesiredFrameRate.TabIndex = 6;
			this.cbxDesiredFrameSize.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxDesiredFrameSize.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbxDesiredFrameSize.Items.AddRange(new object[]
			{
				"Uncontrolled",
				"320x180",
				"320x240",
				"352x240",
				"352x288",
				"640x360",
				"640x480",
				"704x480",
				"704x576",
				"720x576",
				"768x576",
				"800x600",
				"960x720",
				"1024x768",
				"1280x720",
				"1280x960",
				"1280x1024",
				"1600x1200",
				"1920x1080",
				"2048x1536"
			});
			this.cbxDesiredFrameSize.Location = new System.Drawing.Point(286, 108);
			this.cbxDesiredFrameSize.Name = "cbxDesiredFrameSize";
			this.cbxDesiredFrameSize.Size = new System.Drawing.Size(110, 24);
			this.cbxDesiredFrameSize.TabIndex = 7;
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(157, 111);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(123, 16);
			this.label3.TabIndex = 8;
			this.label3.Text = "Desired Frame Size";
			this.chkUsingDeinterlaceFilter.AutoSize = true;
			this.chkUsingDeinterlaceFilter.Location = new System.Drawing.Point(157, 146);
			this.chkUsingDeinterlaceFilter.Name = "chkUsingDeinterlaceFilter";
			this.chkUsingDeinterlaceFilter.Size = new System.Drawing.Size(166, 20);
			this.chkUsingDeinterlaceFilter.TabIndex = 9;
			this.chkUsingDeinterlaceFilter.Text = "Using De-Interlace Filter";
			this.chkUsingDeinterlaceFilter.UseVisualStyleBackColor = true;
			this.chkUsingDeinterlaceFilter.CheckedChanged += new EventHandler(this.chkUsingDeinterlaceFilter_CheckedChanged);
			this.cbxDeinterlaceFilterName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxDeinterlaceFilterName.FormattingEnabled = true;
			this.cbxDeinterlaceFilterName.Items.AddRange(new object[]
			{
				"Deinterlace Filter",
				"blend",
				"bob",
				"discard",
				"linear",
				"mean",
				"x",
				"yadif",
				"yadif2x"
			});
			this.cbxDeinterlaceFilterName.Location = new System.Drawing.Point(157, 172);
			this.cbxDeinterlaceFilterName.Name = "cbxDeinterlaceFilterName";
			this.cbxDeinterlaceFilterName.Size = new System.Drawing.Size(239, 24);
			this.cbxDeinterlaceFilterName.TabIndex = 10;
			this.label4.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(7, 175);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(148, 16);
			this.label4.TabIndex = 11;
			this.label4.Text = "De-Interlace Filter Name";
			this.btnFindFilter.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.btnFindFilter.Location = new System.Drawing.Point(321, 138);
			this.btnFindFilter.Name = "btnFindFilter";
			this.btnFindFilter.Size = new System.Drawing.Size(75, 28);
			this.btnFindFilter.TabIndex = 12;
			this.btnFindFilter.Text = "Find Filter";
			this.btnFindFilter.UseVisualStyleBackColor = true;
			this.btnFindFilter.Click += new EventHandler(this.btnFindFilter_Click);
			this.label5.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(7, 205);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(93, 16);
			this.label5.TabIndex = 13;
			this.label5.Text = "Video Decoder";
			this.cbxVideoDecoder.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxVideoDecoder.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbxVideoDecoder.FormattingEnabled = true;
			this.cbxVideoDecoder.Items.AddRange(new object[]
			{
				"DirectShow",
				"VLC",
				"VLC Player"
			});
			this.cbxVideoDecoder.Location = new System.Drawing.Point(157, 202);
			this.cbxVideoDecoder.Name = "cbxVideoDecoder";
			this.cbxVideoDecoder.Size = new System.Drawing.Size(239, 24);
			this.cbxVideoDecoder.TabIndex = 14;
			this.cbxChanel.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbxChanel.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbxChanel.Items.AddRange(new object[]
			{
				"0",
				"1",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9",
				"10",
				"11",
				"12",
				"13",
				"14",
				"15",
				"16"
			});
			this.cbxChanel.Location = new System.Drawing.Point(286, 48);
			this.cbxChanel.Name = "cbxChanel";
			this.cbxChanel.Size = new System.Drawing.Size(110, 24);
			this.cbxChanel.TabIndex = 41;
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(243, 51);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(38, 16);
			this.label6.TabIndex = 40;
			this.label6.Text = "Kênh";
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 16f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.Controls.Add(this.cbxChanel);
			base.Controls.Add(this.label6);
			base.Controls.Add(this.cbxVideoDecoder);
			base.Controls.Add(this.label5);
			base.Controls.Add(this.btnFindFilter);
			base.Controls.Add(this.label4);
			base.Controls.Add(this.cbxDeinterlaceFilterName);
			base.Controls.Add(this.chkUsingDeinterlaceFilter);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.cbxDesiredFrameSize);
			base.Controls.Add(this.cbxDesiredFrameRate);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.cbxDevice);
			this.Font = new System.Drawing.Font("Arial", 9.75f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
			base.Margin = new Padding(4);
			base.Name = "VideoCaptureDeviceSettingPage";
			base.Size = new System.Drawing.Size(412, 283);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public void Display()
		{
			this.cbxDevice.Focus();
		}
		public bool Apply()
		{
			return true;
		}
		private void chkUsingDeinterlaceFilter_CheckedChanged(object sender, EventArgs e)
		{
			this.cbxDeinterlaceFilterName.Enabled = (this.btnFindFilter.Enabled = this.chkUsingDeinterlaceFilter.Checked);
		}
		private void btnFindFilter_Click(object sender, EventArgs e)
		{
			bool flag = true;
			string text = this.cbxDeinterlaceFilterName.Text;
			if (text != string.Empty)
			{
				FilterInfoCollection filterInfoCollection = new FilterInfoCollection(FilterCategory.LegacyAmFilterCategory);
				foreach (FilterInfo filterInfo in filterInfoCollection)
				{
					if (filterInfo.Name.StartsWith(text))
					{
						flag = false;
						break;
					}
				}
			}
			if (!flag)
			{
				MessageBox.Show("OK");
				return;
			}
			MessageBox.Show("Deinterlace Filter '" + text + "' not found.");
		}
	}
}
